@echo off
REM 景点数据优化一键执行脚本 (Windows)
REM 使用方法: optimize_attractions.bat

echo ==========================================
echo 景点数据优化脚本
echo ==========================================
echo.

REM 备份数据库
echo 步骤1: 备份数据库...
set BACKUP_FILE=backup_attractions_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%.json
set BACKUP_FILE=%BACKUP_FILE: =0%
python manage.py dumpdata attractions > %BACKUP_FILE%
if %errorlevel% equ 0 (
    echo ✓ 备份成功: %BACKUP_FILE%
) else (
    echo ✗ 备份失败，请检查数据库连接
    pause
    exit /b 1
)
echo.

REM 预览去重操作
echo 步骤2: 预览去重操作...
python manage.py deduplicate_attractions --dry-run
echo.

set /p CONFIRM="是否执行去重操作? (y/n): "
if /i "%CONFIRM%"=="y" (
    echo 执行去重...
    python manage.py deduplicate_attractions
    echo ✓ 去重完成
) else (
    echo 跳过去重操作
)
echo.

REM 丰富各类别数据
echo 步骤3: 丰富各类别景点数据...
echo 注意: 这可能需要较长时间，请耐心等待
echo.

set /p CONFIRM="是否同步自然风光类别? (y/n): "
if /i "%CONFIRM%"=="y" (
    python manage.py enrich_attractions_by_category --category natural --max-count 50
)

set /p CONFIRM="是否同步现代建筑类别? (y/n): "
if /i "%CONFIRM%"=="y" (
    python manage.py enrich_attractions_by_category --category modern --max-count 50
)

set /p CONFIRM="是否同步美食购物类别? (y/n): "
if /i "%CONFIRM%"=="y" (
    python manage.py enrich_attractions_by_category --category food --max-count 50
)

echo.
echo ==========================================
echo 优化完成！
echo ==========================================
echo.
echo 备份文件: %BACKUP_FILE%
echo.
echo 验证结果:
python manage.py shell -c "from apps.attractions.models import Attraction; from django.db.models import Count; print('\n各类别景点数量:'); [print(f'  {cat}: {Attraction.objects.filter(category=cat).count()}') for cat in ['cultural', 'natural', 'modern', 'food']]; print(f'\n总景点数量: {Attraction.objects.count()}')"

pause

